Imports System.IO
Imports System.Windows.Forms

#Region "Enums"

''' <summary>
''' NO COMMENTS
''' </summary>
''' <remarks></remarks>
Public Enum eApprovalType
    Admin = 0
    Approved = 1
    Pending = 2
    Revoked = 3
    Rejected = 4
End Enum

''' <summary>
''' Entertainment type
''' </summary>
''' <remarks></remarks>
Public Enum eEntertainmentType
    ''' <summary>
    ''' Movies
    ''' </summary>
    ''' <remarks></remarks>
    Muvees = 0
    ''' <summary>
    ''' TV Series
    ''' </summary>
    ''' <remarks></remarks>
    TVSeries = 1
    ''' <summary>
    ''' Games
    ''' </summary>
    ''' <remarks></remarks>
    Games = 2
    ''' <summary>
    ''' Softwares
    ''' </summary>
    ''' <remarks></remarks>
    Softwares = 3
End Enum

''' <summary>
''' NO COMMENTS
''' </summary>
''' <remarks></remarks>
Public Enum eActionModes
    mNew = 0
    mEdit = 1
End Enum

''' <summary>
''' Range Templates of allowed values
''' </summary>
''' <remarks></remarks>
Public Enum eRangeType
    ''' <summary>
    ''' Minimum allowed value
    ''' </summary>
    ''' <remarks></remarks>
    Minimum = -1
    ''' <summary>
    ''' Default selected value
    ''' </summary>
    ''' <remarks></remarks>
    [Default] = 0
    ''' <summary>
    ''' Maximum allowed value
    ''' </summary>
    ''' <remarks></remarks>
    Maximum = 1
End Enum

''' <summary>
''' NO COMMENTS
''' </summary>
''' <remarks></remarks>
Public Enum eRangeMeta
    nDiscs
    ReleaseYear
    RunTime
    TVEpisode
    TVSeason
    WatchlistCalendar
End Enum

''' <summary>
''' NO COMMENTS
''' </summary>
''' <remarks></remarks>
Public Enum eKeypressValidation
    Numeric = 0
    Alphabetical = 1
    AlphaNumeric = 2
End Enum

#End Region

Public Class ULMain

    ''' <summary>
    ''' NO COMMENTS
    ''' </summary>
    ''' <remarks></remarks>
    Public Enum eCharacterType
        LCaseAlpha = 0
        UCaseAlpha = 1
        Numeral = 2
        SpChar = 3

        AlphaNumeric = 100
        AlphaOnly = 101
        NumericOnly = 102
    End Enum

#Region "Directory/File Validations"

    ''' <summary>
    ''' Checks if the file exists at the specified location
    ''' </summary>
    ''' <param name="sPath">Physical path of the file</param>
    ''' <returns>TRUE: if exists</returns>
    ''' <remarks></remarks>
    Public Shared Function IsFileExists(ByVal sPath As String) As Boolean
        If File.Exists(sPath) Then Return True Else Return False
    End Function

    ''' <summary>
    ''' Checks if the specified directory is valid
    ''' </summary>
    ''' <param name="sDirPath">Physical path of the directory</param>
    ''' <param name="bCreate">TRUE: Create directory, if Parent Directory exists</param>
    ''' <returns>TRUE: if valid</returns>
    ''' <remarks></remarks>
    Public Shared Function IsDirectoryExists(ByVal sDirPath As String, Optional ByVal bCreate As Boolean = False) As Boolean
        If Directory.Exists(sDirPath) Then
            Return True
        Else
            If bCreate Then
                If Directory.Exists(Directory.GetParent(sDirPath).Name) Then
                    'create directory if parent exists
                    Directory.CreateDirectory(sDirPath)
                    If Directory.Exists(sDirPath) Then Return True Else Return False
                Else
                    Return False
                End If
            Else
                Return False
            End If
        End If
    End Function

#End Region

#Region "Data Validations"

    ''' <summary>
    ''' Checks if a object is null
    ''' </summary>
    ''' <param name="objCheck">Object to check</param>
    ''' <returns>True, if empty</returns>
    ''' <remarks></remarks>
    Public Shared Function IsEmpty(ByVal objCheck As Object) As Boolean
        If objCheck Is Nothing Or IsDBNull(objCheck) Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' Checks if a date has mimimum value
    ''' </summary>
    ''' <param name="dateCheck">Date to check</param>
    ''' <returns>True, if empty</returns>
    ''' <remarks></remarks>
    Public Shared Function IsEmpty(ByVal dateCheck As Date) As Boolean
        If CDate(dateCheck) = Date.MinValue Then Return True Else Return False
    End Function

    ''' <summary>
    ''' Checks if a date has mimimum value
    ''' </summary>
    ''' <param name="strCheck"></param>
    ''' <returns>True, if empty</returns>
    ''' <remarks></remarks>
    Public Shared Function IsEmpty(ByVal strCheck As String) As Boolean
        If strCheck Is Nothing Then
            Return True
        Else
            If strCheck.Trim = "" Then Return True Else Return False
        End If
    End Function

    ''' <summary>
    ''' Checks if a DataTable is empty
    ''' </summary>
    ''' <param name="dtTable">DataTable to check</param>
    ''' <returns>True, if empty</returns>
    ''' <remarks></remarks>
    Public Shared Function IsEmpty(ByVal dtTable As DataTable) As Boolean
        If dtTable Is Nothing OrElse dtTable.Rows.Count = 0 Then Return True Else Return False
    End Function

    ''' <summary>
    ''' NO COMMENTS
    ''' </summary>
    ''' <param name="sList"></param>
    ''' <param name="sItem"></param>
    ''' <param name="cDelimeter"></param>
    ''' <param name="iCompareMethod"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function InArray(ByVal sList As String, ByVal sItem As String, Optional ByVal cDelimeter As Char = ","c, Optional ByVal iCompareMethod As CompareMethod = CompareMethod.Text) As Boolean
        Dim arrItems() As String

        Try
            arrItems = sList.Split(cDelimeter)
            Return InArray(arrItems, sItem)
        Finally
            Erase arrItems
            sItem = Nothing
            cDelimeter = Nothing
        End Try
    End Function

    ''' <summary>
    ''' NO COMMENTS
    ''' </summary>
    ''' <param name="arrItems"></param>
    ''' <param name="sItem"></param>
    ''' <param name="iCompareMethod"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function InArray(ByVal arrItems() As String, ByVal sItem As String, Optional ByVal iCompareMethod As CompareMethod = CompareMethod.Binary) As Boolean
        Try
            ''For Each item As String In arrItems
            ''    Select Case iCompareMethod
            ''        Case CompareMethod.Binary
            ''            If sItem = item Then Return True
            ''
            ''        Case CompareMethod.Text
            ''            If sItem.ToLower = item.ToLower Then Return True
            ''
            ''    End Select
            ''Next
            ''Return False

            Select Case iCompareMethod
                Case CompareMethod.Binary
                    Return Not Array.BinarySearch(arrItems, sItem) < 0
                Case CompareMethod.Text
                    For Each item As String In arrItems
                        item = item.ToLower
                    Next
                    Return Not Array.BinarySearch(arrItems, sItem.ToLower) < 0
            End Select

        Catch ex As Exception
            Return False
        Finally
            Erase arrItems
            sItem = Nothing
        End Try
    End Function

    ''' <summary>
    ''' NO COMMENTS
    ''' </summary>
    ''' <param name="e"></param>
    ''' <param name="iKeypressValidation"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function IsKeyAllowed(ByRef e As System.Windows.Forms.KeyPressEventArgs, ByVal iKeypressValidation As eKeypressValidation) As Boolean
        Select Case Convert.ToInt32(e.KeyChar)
            Case Keys.Escape, Keys.Back, _
                   Keys.Delete, Keys.Insert, _
                   Keys.Home, Keys.End, _
                   Keys.Left, Keys.Right 'Navigation
                e.Handled = False

            Case Else
                Select Case iKeypressValidation
                    Case eKeypressValidation.AlphaNumeric
                    Case eKeypressValidation.Alphabetical
                    Case eKeypressValidation.Numeric
                        Select Case Convert.ToInt32(e.KeyChar)
                            Case 48 To 57
                                e.Handled = False
                            Case Else
                                e.Handled = True
                        End Select
                End Select
        End Select
        Return e.Handled

        Exit Function
        'RKD: OPTION 1:
        If Char.IsLetterOrDigit(Convert.ToChar(e.KeyChar)) Then
            If Char.IsLetter(Convert.ToChar(e.KeyChar)) Then

            End If
            If Char.IsDigit(Convert.ToChar(e.KeyChar)) Then

            End If
        End If
        If Char.IsLower(Convert.ToChar(e.KeyChar)) Or Char.IsUpper(Convert.ToChar(e.KeyChar)) Then

        End If
        If Char.IsPunctuation(Convert.ToChar(e.KeyChar)) Or Char.IsSeparator(Convert.ToChar(e.KeyChar)) Or Char.IsSymbol(Convert.ToChar(e.KeyChar)) Or Char.IsWhiteSpace(Convert.ToChar(e.KeyChar)) Then

        End If

        'RKD: OPTION 2:
        Dim iKeyAscii As Integer = Convert.ToInt32(e.KeyChar)
        Select Case iKeyAscii
            Case 48 To 57  ' numbers
            Case 65 To 90, 97 To 122 ' letters

                '=-=-=-=-=-=-=-= Numeric Keys
            Case Keys.D0
            Case Keys.D1
            Case Keys.D2
            Case Keys.D3
            Case Keys.D4
            Case Keys.D5
            Case Keys.D6
            Case Keys.D7
            Case Keys.D8
            Case Keys.D9
            Case Keys.NumPad0
            Case Keys.NumPad1
            Case Keys.NumPad2
            Case Keys.NumPad3
            Case Keys.NumPad4
            Case Keys.NumPad5
            Case Keys.NumPad6
            Case Keys.NumPad7
            Case Keys.NumPad8
            Case Keys.NumPad9

                '=-=-=-=-=-=-=-= Symbols/Special Characters
            Case Keys.OemBackslash
            Case Keys.OemClear
            Case Keys.OemCloseBrackets
            Case Keys.Oemcomma
            Case Keys.OemMinus
            Case Keys.OemOpenBrackets
            Case Keys.OemPeriod
            Case Keys.OemPipe
            Case Keys.Oemplus
            Case Keys.OemQuestion
            Case Keys.OemQuotes
            Case Keys.OemSemicolon
            Case Keys.Oemtilde

                '=-=-=-=-=-=-=-= Function Keys: F1-F24
            Case Keys.F1
            Case Keys.F2
            Case Keys.F3
            Case Keys.F4
            Case Keys.F5
            Case Keys.F6
            Case Keys.F7
            Case Keys.F8
            Case Keys.F9
            Case Keys.F10
            Case Keys.F11
            Case Keys.F12
            Case Keys.F13
            Case Keys.F14
            Case Keys.F15
            Case Keys.F16
            Case Keys.F17
            Case Keys.F18
            Case Keys.F19
            Case Keys.F20
            Case Keys.F21
            Case Keys.F22
            Case Keys.F23
            Case Keys.F24

                '=-=-=-=-=-=-=-= Ctrl/Alt/Shift
            Case Keys.Control
            Case Keys.LControlKey
            Case Keys.RControlKey
            Case Keys.Alt
            Case Keys.LMenu
            Case Keys.RMenu
            Case Keys.Shift
            Case Keys.LShiftKey
            Case Keys.RShiftKey
            Case Keys.LWin
            Case Keys.RWin

                '=-=-=-=-=-=-=-= Navigation
            Case Keys.Escape
            Case Keys.Back
            Case Keys.Delete
            Case Keys.Insert
            Case Keys.Home
            Case Keys.End
            Case Keys.PageUp
            Case Keys.PageDown
            Case Keys.Left
            Case Keys.Right
            Case Keys.Up
            Case Keys.Down

                '=-=-=-=-=-=-=-= Locks
            Case Keys.CapsLock
            Case Keys.NumLock
            Case Keys.Scroll
            Case Keys.PrintScreen
            Case Keys.Pause

                '=-=-=-=-=-=-=-= Media
            Case Keys.VolumeUp
            Case Keys.VolumeDown
            Case Keys.VolumeMute
            Case Keys.MediaPlayPause
            Case Keys.MediaStop
            Case Keys.MediaPreviousTrack
            Case Keys.MediaNextTrack

                '=-=-=-=-=-=-=-= Mouse
            Case Keys.LButton
            Case Keys.MButton
            Case Keys.RButton
        End Select
    End Function

#End Region









    ''' <summary>
    ''' NO COMMENTS
    ''' </summary>
    ''' <param name="sTextToValidate"></param>
    ''' <param name="iCharacterType"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function CheckValidCharacters(ByVal sTextToValidate As String, ByVal iCharacterType As eCharacterType) As Boolean
        'RKD: loop thru all chars
        MsgBox("BLMain.CheckValidCharacters", , "INCOMPLETE")
        Return True

        Dim e As KeyPressEventArgs
        If Char.IsLetterOrDigit(Convert.ToChar(e.KeyChar)) Then
            If Char.IsLetter(Convert.ToChar(e.KeyChar)) Then

            End If
            If Char.IsDigit(Convert.ToChar(e.KeyChar)) Then

            End If
        End If
        If Char.IsLower(Convert.ToChar(e.KeyChar)) Or Char.IsUpper(Convert.ToChar(e.KeyChar)) Then

        End If
        If Char.IsPunctuation(Convert.ToChar(e.KeyChar)) Or Char.IsSeparator(Convert.ToChar(e.KeyChar)) Or Char.IsSymbol(Convert.ToChar(e.KeyChar)) Or Char.IsWhiteSpace(Convert.ToChar(e.KeyChar)) Then

        End If

        'RKD: OPTION 2:
        Dim iKeyAscii As Integer = Convert.ToInt32(e.KeyChar)
        Select Case iKeyAscii
            Case 48 To 57  ' numbers
            Case 65 To 90, 97 To 122 ' letters

                '=-=-=-=-=-=-=-= Numeric Keys
            Case System.Windows.Forms.Keys.D0
            Case System.Windows.Forms.Keys.D1
            Case System.Windows.Forms.Keys.D2
            Case System.Windows.Forms.Keys.D3
            Case System.Windows.Forms.Keys.D4
            Case System.Windows.Forms.Keys.D5
            Case System.Windows.Forms.Keys.D6
            Case System.Windows.Forms.Keys.D7
            Case System.Windows.Forms.Keys.D8
            Case System.Windows.Forms.Keys.D9
            Case System.Windows.Forms.Keys.NumPad0
            Case System.Windows.Forms.Keys.NumPad1
            Case System.Windows.Forms.Keys.NumPad2
            Case System.Windows.Forms.Keys.NumPad3
            Case System.Windows.Forms.Keys.NumPad4
            Case System.Windows.Forms.Keys.NumPad5
            Case System.Windows.Forms.Keys.NumPad6
            Case System.Windows.Forms.Keys.NumPad7
            Case System.Windows.Forms.Keys.NumPad8
            Case System.Windows.Forms.Keys.NumPad9

                '=-=-=-=-=-=-=-= Symbols/Special Characters
            Case System.Windows.Forms.Keys.OemBackslash
            Case System.Windows.Forms.Keys.OemClear
            Case System.Windows.Forms.Keys.OemCloseBrackets
            Case System.Windows.Forms.Keys.Oemcomma
            Case System.Windows.Forms.Keys.OemMinus
            Case System.Windows.Forms.Keys.OemOpenBrackets
            Case System.Windows.Forms.Keys.OemPeriod
            Case System.Windows.Forms.Keys.OemPipe
            Case System.Windows.Forms.Keys.Oemplus
            Case System.Windows.Forms.Keys.OemQuestion
            Case System.Windows.Forms.Keys.OemQuotes
            Case System.Windows.Forms.Keys.OemSemicolon
            Case System.Windows.Forms.Keys.Oemtilde

                '=-=-=-=-=-=-=-= Function Keys: F1-F24
            Case System.Windows.Forms.Keys.F1
            Case System.Windows.Forms.Keys.F2
            Case System.Windows.Forms.Keys.F3
            Case System.Windows.Forms.Keys.F4
            Case System.Windows.Forms.Keys.F5
            Case System.Windows.Forms.Keys.F6
            Case System.Windows.Forms.Keys.F7
            Case System.Windows.Forms.Keys.F8
            Case System.Windows.Forms.Keys.F9
            Case System.Windows.Forms.Keys.F10
            Case System.Windows.Forms.Keys.F11
            Case System.Windows.Forms.Keys.F12
            Case System.Windows.Forms.Keys.F13
            Case System.Windows.Forms.Keys.F14
            Case System.Windows.Forms.Keys.F15
            Case System.Windows.Forms.Keys.F16
            Case System.Windows.Forms.Keys.F17
            Case System.Windows.Forms.Keys.F18
            Case System.Windows.Forms.Keys.F19
            Case System.Windows.Forms.Keys.F20
            Case System.Windows.Forms.Keys.F21
            Case System.Windows.Forms.Keys.F22
            Case System.Windows.Forms.Keys.F23
            Case System.Windows.Forms.Keys.F24

                '=-=-=-=-=-=-=-= Ctrl/Alt/Shift
            Case System.Windows.Forms.Keys.Control
            Case System.Windows.Forms.Keys.LControlKey
            Case System.Windows.Forms.Keys.RControlKey
            Case System.Windows.Forms.Keys.Alt
            Case System.Windows.Forms.Keys.LMenu
            Case System.Windows.Forms.Keys.RMenu
            Case System.Windows.Forms.Keys.Shift
            Case System.Windows.Forms.Keys.LShiftKey
            Case System.Windows.Forms.Keys.RShiftKey
            Case System.Windows.Forms.Keys.LWin
            Case System.Windows.Forms.Keys.RWin

                '=-=-=-=-=-=-=-= Navigation
            Case System.Windows.Forms.Keys.Escape
            Case System.Windows.Forms.Keys.Back
            Case System.Windows.Forms.Keys.Delete
            Case System.Windows.Forms.Keys.Insert
            Case System.Windows.Forms.Keys.Home
            Case System.Windows.Forms.Keys.End
            Case System.Windows.Forms.Keys.PageUp
            Case System.Windows.Forms.Keys.PageDown
            Case System.Windows.Forms.Keys.Left
            Case System.Windows.Forms.Keys.Right
            Case System.Windows.Forms.Keys.Up
            Case System.Windows.Forms.Keys.Down

                '=-=-=-=-=-=-=-= Locks
            Case System.Windows.Forms.Keys.CapsLock
            Case System.Windows.Forms.Keys.NumLock
            Case System.Windows.Forms.Keys.Scroll
            Case System.Windows.Forms.Keys.PrintScreen
            Case System.Windows.Forms.Keys.Pause

                '=-=-=-=-=-=-=-= Media
            Case System.Windows.Forms.Keys.VolumeUp
            Case System.Windows.Forms.Keys.VolumeDown
            Case System.Windows.Forms.Keys.VolumeMute
            Case System.Windows.Forms.Keys.MediaPlayPause
            Case System.Windows.Forms.Keys.MediaStop
            Case System.Windows.Forms.Keys.MediaPreviousTrack
            Case System.Windows.Forms.Keys.MediaNextTrack

                '=-=-=-=-=-=-=-= Mouse
            Case System.Windows.Forms.Keys.LButton
            Case System.Windows.Forms.Keys.MButton
            Case System.Windows.Forms.Keys.RButton
        End Select
    End Function
End Class